package com.mdb.open.trade.service.trade;


/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfLoanApplyCustomsInfoService.java
* Author:   you.yichao
* Date:     2019-10-11
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-10-11          V1.00             代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.database.mybatisplus.SuperService;
import com.mdb.open.trade.common.MdbDataSource;
import com.mdb.open.trade.domain.bo.trade.LoanApplyCustomsInfoBo;
import com.mdb.open.trade.domain.po.trade.LoanApplyCustomsInfo;
import com.mdb.open.trade.mapper.trade.TfLoanApplyCustomsInfoMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述：
 *  贸易融资申请报关信息表 服务类
 *
 * @author you.yichao
 * @date 2019-10-11
 */
@Service
@DS(MdbDataSource.TRADE)
public class TfLoanApplyCustomsInfoService extends SuperService<TfLoanApplyCustomsInfoMapper, LoanApplyCustomsInfo> {

    public ResultEx saveCustomsInfo(LoanApplyCustomsInfoBo bo) {

        LoanApplyCustomsInfo customsInfo = new LoanApplyCustomsInfo();
        customsInfo.setApplyOrderNo(bo.getApplyOrderNo());
        customsInfo.setBusinessNo(bo.getBusinessNo());
        customsInfo.setCustomerCode(bo.getCustomerCode());
        customsInfo.setCustomerName(bo.getCustomerName());
        customsInfo.setMerchantNo(bo.getMerchantNo());
        customsInfo.setCustomsNo(bo.getCustomsNo());
        customsInfo.setMerchantName(bo.getMerchantName());
        customsInfo.setCustomsLocation(bo.getCustomsLocation());
        customsInfo.setCustomsTitle(bo.getCustomsTitle());
        customsInfo.setCustomsAmount(bo.getCustomsAmount());
        customsInfo.setCcy(bo.getCcy());
        customsInfo.setCommitTime(bo.getCommitTime());
        customsInfo.setLoadingPort(bo.getLoadingPort());
        customsInfo.setLoadingPortCode(bo.getLoadingPortCode());
        customsInfo.setDestinPort(bo.getDestinPort());
        customsInfo.setDestinPortCode(bo.getDestinPortCode());
        customsInfo.setDestinCountry(bo.getDestinCountry());
        customsInfo.setSourceType(bo.getSourceType());

        int count = this.baseMapper.insert(customsInfo);
        if (count != 1) {
            return ResultEx.fail();
        }
        return ResultEx.ok();
    }

    public ResultEx cntCustoms(List<String> customsNoList) {

        int cnt = this.baseMapper.selectCount(new LambdaQueryWrapper<LoanApplyCustomsInfo>()
                .in(LoanApplyCustomsInfo::getCustomsNo, customsNoList));

        if (cnt > 0) {
            return ResultEx.fail();
        } else {
            return ResultEx.ok();
        }

    }


}
